<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //隐式转换
        //'+'号两边只要有一边是字符串，另一边也会变成字符串
        console.log('2' + 2)  //输出22
        //'-'号两边只要有一边是数字，另一边也会变成数字
        console.log('2' - 2)  //输出0
        //'+'号作为正号解析可以转化为数字
        let str = '123'
        console.log(typeof str)   //输出为string
        console.log(typeof +str)  //输出为number

        //显示转换
        let age = Number(prompt('请输入年龄：'))
        console.log(typeof age)
        console.log(parseInt('12'))
        console.log(parseInt('12.34'))
        console.log(Number('12.34'))
        console.log(parseFloat('12.34'))
        console.log(Number('12.34px'))  //NAN
        console.log(parseFloat('12.34px'))  //12.34
    </script>
</body>
</html>